package com.burstly.lib.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.burstly.lib.component.networkcomponent.burstly.OverlayContainer;
import com.burstly.lib.component.networkcomponent.burstly.OverlayContainer.IOverlayListener;
import com.burstly.lib.component.networkcomponent.burstly.html.IDestroyableActivityLifecycleAware;

public class UiSafeWebView extends WebView
  implements IDestroyableActivityLifecycleAware, OverlayContainer.IOverlayListener
{
  private OverlayContainer<?> mHostingOverlay;
  private boolean mInterstitial;
  private final Handler mUiHandler = new Handler(Looper.getMainLooper());
  private volatile boolean mWasDestroyed;

  public UiSafeWebView(Context paramContext)
  {
    super(paramContext);
    getSettings().setJavaScriptEnabled(true);
  }

  private static boolean shouldPostInMainThread()
  {
    return (Build.VERSION.SDK_INT >= 14) && (!Thread.currentThread().getName().equals("main"));
  }

  public OverlayContainer<?> getHostingOverlay()
  {
    return this.mHostingOverlay;
  }

  public boolean isInterstitial()
  {
    return this.mInterstitial;
  }

  public void loadData(final String paramString1, final String paramString2, final String paramString3)
  {
    if (!this.mWasDestroyed)
    {
      if (shouldPostInMainThread())
        this.mUiHandler.post(new SafeRunnable(this)
        {
          public void doRun()
          {
            UiSafeWebView.this.loadData(paramString1, paramString2, paramString3);
          }
        });
    }
    else
      return;
    super.loadData(paramString1, paramString2, paramString3);
  }

  public void loadDataWithBaseURL(final String paramString1, final String paramString2, final String paramString3, final String paramString4, final String paramString5)
  {
    if (!this.mWasDestroyed)
    {
      if (shouldPostInMainThread())
        this.mUiHandler.post(new SafeRunnable(this)
        {
          public void doRun()
          {
            UiSafeWebView.this.loadDataWithBaseURL(paramString1, paramString2, paramString3, paramString4, paramString5);
          }
        });
    }
    else
      return;
    super.loadDataWithBaseURL(paramString1, paramString2, paramString3, paramString4, paramString5);
  }

  public void loadUrl(final String paramString)
  {
    if (!this.mWasDestroyed)
    {
      if (shouldPostInMainThread())
        this.mUiHandler.post(new SafeRunnable(this)
        {
          public void doRun()
          {
            UiSafeWebView.this.loadUrl(paramString);
          }
        });
    }
    else
      return;
    try
    {
      super.loadUrl(paramString);
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public void onCloseOverlay()
  {
    onDestroy((Activity)getContext());
  }

  public void onDestroy(Activity paramActivity)
  {
    this.mWasDestroyed = true;
  }

  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    if (Build.VERSION.SDK_INT >= 11)
      invalidate();
  }

  public boolean onKey(Activity paramActivity, int paramInt, KeyEvent paramKeyEvent)
  {
    return false;
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    return ((this.mInterstitial) && (paramInt == 82)) || (super.onKeyDown(paramInt, paramKeyEvent));
  }

  @TargetApi(11)
  public void onPause(Activity paramActivity)
  {
    if (Build.VERSION.SDK_INT > 10)
      onPause();
  }

  @TargetApi(11)
  public void onResume(Activity paramActivity)
  {
    if (Build.VERSION.SDK_INT > 10)
      onResume();
  }

  public void onShowOverlay()
  {
  }

  public void setHostingOverlay(OverlayContainer<?> paramOverlayContainer)
  {
    this.mHostingOverlay = paramOverlayContainer;
  }

  public void setInterstitial(boolean paramBoolean)
  {
    this.mInterstitial = paramBoolean;
  }

  public boolean wasDestroyed()
  {
    return this.mWasDestroyed;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.util.UiSafeWebView
 * JD-Core Version:    0.6.2
 */